<?php
            
use app\model\Theme; 


/**
 * Desc:奖品兑换
 * Time: 2021/3/23 8:33 上午
 */
class Convert_Page extends PluginMobilePage {

    function main($method)
    {
        global $_P,$_G,$_S,$_C;
        $fromtype = $_P['from'];
        if ($fromtype=='mobile') {
            $themeid = isset($_P['themeid'])?$_P['themeid']:'';
            $theme = Theme::getThemeById($themeid);
            $workerid = isset($_P['workerid'])?$_P['workerid']:'';
            if (!$themeid || !$theme) {
                return_json(1,'活动入口不正确');
            } else {
                $f_id = $_P['f_id']?$_P['f_id']:0;
                $fans = $this->checkuser();
                if ($fans && $fans['uid'] && $f_id){
                    $uid = $fans['uid'];
                    $res = LotteryModel::ConvertPrize($theme,$_C,$uid,$f_id,$_S,$fromtype);
                    return_json(0,'操作成功',$res);
                }
                return_json(1,'操作失败',[]);
            }
        } elseif ($fromtype=='wxapp') {
            $themeid = isset($_P['themeid'])?$_P['themeid']:'';
            $theme = Theme::getThemeById($themeid);
            $workerid = isset($_P['workerid'])?$_P['workerid']:'';
            if (!$themeid || !$theme) {
                return_json(1,'活动入口不正确');
            } else {
                $f_id = $_P['f_id']?$_P['f_id']:0;
                $fans = $this->checkuser();
                if ($fans && $fans['uid'] && $f_id){
                    $uid = $fans['uid'];
                    $res = LotteryModel::ConvertPrize($theme,$_C,$uid,$f_id,$_S,$fromtype);
                    return_json(0,'操作成功',$res);
                }
                return_json(1,'操作失败',[]);
            }
        }
    }
}